//
//  getMemInfo.m
//  YinHang
//
//  Created by idea on 14-9-28.
//  Copyright (c) 2014年 孙彦鹏. All rights reserved.
//

#import "getMemInfo.h"

@implementation getMemInfo{
    ASIFormDataRequest *userInfoRequest;
}

- (void)dealloc {
    [userInfoRequest cancel];
    
    NSLog(@"CatListService dealloc...");
}

-(void)getUserDate{
    /* 获取全部类别 */
    
    // 检查网络
    if (![Constants isExistenceNetwork]) {
        
    } else {
        
        userInfoRequest = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:API_STR]];
        userInfoRequest.requestMethod = @"POST";
        // 设置超时时间
        userInfoRequest.timeOutSeconds = 60;
        userInfoRequest.delegate = self;
        // 设置参数
        NSString *action = @"getuser";
        //NSDictionary *paramsDict =  @{@"uid": @"互联天下",@"pagenow": self.pageInfo.pageno, @"pagesize": self.pageInfo.pagesize};
        NSDictionary *paramsDict =  @{@"uid": UNAME};
        //        NSLog(@"%@| %@",self.pageInfo.pageno,self.pageInfo.pagesize);
        NSString *paramsStr = [NSString JSONString:paramsDict];
        NSString *result = [NSString stringWithFormat:TEMPLATE_PARAMSTR, action,paramsStr];
        
        NSData *paramsData = [result toGBKEncodingData];
        userInfoRequest.postBody = [paramsData mutableCopy];
        
        [userInfoRequest startAsynchronous];//startAsynchronous];
        
        
    }
}
- (NSMutableDictionary*)dataArr{
    if (!_dataArr) {
        _dataArr = [NSMutableDictionary dictionary];
    }
    return _dataArr;
}

#pragma mark - ASIHTTPRequestDelegate Method

- (void)requestFinished:(ASIHTTPRequest *)request {
    NSLog(@"%@",request.responseString);
    /*
    NSString * responseString = [request responseString];
    responseString = [responseString stringByReplacingOccurrencesOfString:@"<div>" withString:@""];
    responseString = [responseString stringByReplacingOccurrencesOfString:@"\n" withString:@""];
    responseString = [responseString stringByReplacingOccurrencesOfString:@"<br />" withString:@""];
    responseString = [responseString stringByReplacingOccurrencesOfString:@"</div>" withString:@""];
    responseString = [responseString stringByReplacingOccurrencesOfString:@"&nbsp;" withString:@""];
    NSLog(@"responseString = %@",responseString);
     */
    //self.dataArr =  request.responseData;
   // NSLog(@"%@",_dataArr);
   // NSLog(@"%@",_dataArr[@"Isok"]);
    NSError *err;
    NSDictionary *result = [NSJSONSerialization JSONObjectWithData:[request.responseString dataForUTF8] options:NSJSONReadingAllowFragments error:&err];
    //NSLog(@"\n%@",result);
    // 1. 是否解析有错误
    if (!err) {
        
        // 2. 判断错误码
        NSInteger errorCode = [result[@"errorCode"]integerValue];
        if (errorCode == 0) {
            // 2.1 获取"info"
            NSDictionary *info = result[@"info"];
           // NSLog(@"%@",info);
            
            //NSInteger totalCount = [info[@"total"]integerValue];
            self.dataArr = [info mutableCopy];
            [_delegate receiveData];
            NSLog(@"%@",self.dataArr);
        } else {
            
            NSString *dataStr = result[@"info"][@"data"];
            if ([dataStr isEqualToString:@"0"]) {
                if ([result[@"errorMsg"] isEqualToString:@"该条件下为得到任何数据"]){
                    
                }
            }
        }
        
    } else {
        [SVProgressHUD showErrorWithStatus:@"数据解析出错！"];
        
    }
    
}

- (void)requestFailed:(ASIHTTPRequest *)request{
    [SVProgressHUD showErrorWithStatus:@"服务器无法访问，请稍后再试!"];
    
}




@end
